﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminSSOption : Form
    {
        public AdminSSOption()
        {
            InitializeComponent();

            Thread SSOptionThread = new Thread(new ThreadStart(getAllSSOption_Thread));
            SSOptionThread.Start();
        }


        private void getAllSSOption_Thread()
        {
            Invoke(new MethodInvoker(getAllSSOption));
        }

        private void getAllSSOption()
        {
            Table SSOption = Program.Db.QueryTable("SELECT S.NumSSOption, S.NomSSOption, S.PrixSSOption, O.LibelleOption FROM SSOPTION S LEFT OUTER JOIN OPTIONS O ON S.NumOption = O.NumOption");

           this.dataSSOption.Rows.Clear();

            foreach (Record r in SSOption)
              this.dataSSOption.Rows.Add(r.Values[0], r.Values[1],r.Values[2],r.Values[3]);
        }
        private void AdminSSOption_Activated(object sender, EventArgs e)
        {
            Thread OptionThread = new Thread(new ThreadStart(getAllSSOption_Thread));
            OptionThread.Start();
        }
        private void ButtonAddSSOption_Click(object sender, EventArgs e)
        {
            AddSSOption FenAddSSOption = new AddSSOption();
            FenAddSSOption.ShowDialog();
        }

        private void buttonDelSSOption_Click(object sender, EventArgs e)
        {
           SSOPTION delssoption = new SSOPTION();
           delssoption.delete_SSOption(Convert.ToInt32(this.dataSSOption.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllSSOption_Thread));
            TypeThread.Start();
        }

        private void ButtonDeleteSSOption_Click(object sender, EventArgs e)
        {
            SSOPTION delssoption = new SSOPTION();
            delssoption.delete_SSOption(Convert.ToInt32(this.dataSSOption.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllSSOption_Thread));
            TypeThread.Start();
        }

        private void buttonUpdateSSOption_Click(object sender, EventArgs e)
        {
            AddSSOption FenAddVoiture = new AddSSOption(Convert.ToInt32(this.dataSSOption.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddVoiture.ShowDialog();
        }
    }
}